/*
 * $Id: InfoBar.java 182 2009-06-04 16:30:30Z meyer@alphatec.de $
 * 
 *
 * Copyright 2009 DeltaDesk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package deltadesk.apps.pictureviewer.widget;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;



/**
 * InfoBar.
 * 
 * @author Andreas Meyer
 * @version $Revision: 182 $
 */
public class InfoBar extends AbstractWidget {

	private static final long serialVersionUID = 4339175184691926353L;
	
	/** The first bold text. */
	private String text1;
	
	/** The second normal text. */
	private String text2;


	/**
	 * Construct the infobar.
	 */
	public InfoBar() {
		
		setOpaque(false);
	}

	/**
	 * @see deltadesk.apps.pictureviewer.widget.gui.swing.widget.AbstractWidget#paintComponent(java.awt.Graphics2D)
	 */
	@Override
	protected void paintComponent(final Graphics2D g2) {

		final Font f = getFont();
		
		g2.setFont(f.deriveFont(Font.BOLD));
		final FontMetrics fm = g2.getFontMetrics(g2.getFont());
		int h = fm.getHeight();

		int x = 5;
		int y = h + 1;
		
		if(text1 != null) {

			drawStringAccented(g2, text1, x, y);
			x += fm.stringWidth(text1) + 5;
		} // end if
		
		if(text2 != null) {
			
			g2.setFont(getFont());
			drawStringAccented(g2, text2, x, y);
		} // end if
	}

	/**
	 * @param text1 the text1 to set
	 */
	public void setText1(final String text1) {
		this.text1 = text1;
	}

	/**
	 * @param text2 the text2 to set
	 */
	public void setText2(final String text2) {
		this.text2 = text2;
	}

	/**
	 * Draw a string accented.
	 * 
	 * @param g2
	 * @param text
	 * @param x
	 * @param y
	 */
	private void drawStringAccented(final Graphics2D g2, 
			                        final String text, 
			                        final int x, final int y) {

		//TODO: Use foreground color
		g2.setColor(Color.WHITE);
		g2.drawString(text, x, y + 1);
		g2.setColor(Color.BLACK);
		g2.drawString(text, x, y);
	}

}
